package com.kgc.provider;

import com.alibaba.dubbo.config.annotation.Service;
import com.kgc.api.goods.ShowHomeSoildeshowApi;
import com.kgc.bean.CarouselDTO;
import com.kgc.domain.CarouselPO;
import com.kgc.domain.CarouselPOExample;
import com.kgc.mapper.CarouselMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * Created on 2021/6/23.
 * Author: lzy
 * Description:
 */
@Service
public class ShowHomeSoildeshowProvider implements ShowHomeSoildeshowApi {


    @Autowired
    private CarouselMapper carouselMapper;

    @Override
    public List<CarouselDTO> selectHomeSoildeshow(Integer count) {
        CarouselPOExample carouselPOExample = new CarouselPOExample();
        carouselPOExample.setDistinct(false);
        carouselPOExample.setOrderByClause("pic_sort");
        CarouselPOExample.Criteria criteria = carouselPOExample.createCriteria();
        // 展示
        int num = 0;
        criteria.andIsShowEqualTo(0);
        carouselPOExample.setOffset((long) num);
        carouselPOExample.setLimit(count);

        //转换实体类型
        List<CarouselPO> carouselPOS = carouselMapper.selectByExample(carouselPOExample);

        List<CarouselDTO> carouselDTOS = new ArrayList<>();
        for (int i=0;i<carouselPOS.size();i++){
            CarouselDTO carouselDTO = new CarouselDTO();
            BeanUtils.copyProperties(carouselPOS.get(i),carouselDTO);
            carouselDTOS.add(carouselDTO);
        }
       // List<CarouselDTO> collect = carouselPOS.stream().map((a,b) -> BeanUtils.copyProperties(a,new CarouselDTO())).collect(Collectors.toList());
        return carouselDTOS;
    }
}
